package cn.serein.charging.cost.dao.repository.impl;

import cn.serein.charging.cost.dao.repository.CostRuleCashRepository;
import cn.serein.charging.cost.pojo.po.CostRulePO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Repository;

import java.util.Collections;
import java.util.List;


@Repository
public class CostRuleCashRepositoryImpl implements CostRuleCashRepository {

    @Autowired
    private RedisTemplate<String,List<CostRulePO>> redisTemplate;

    @Override
    public void setCashCostRules(Integer stationId, List<CostRulePO> costRulePOS) {
        ValueOperations<String, List<CostRulePO>> valueOperations = redisTemplate.opsForValue();

        String key = "COST_RULE_KEY_" + stationId;

        valueOperations.set(key,costRulePOS);


    }

    @Override
    public List<CostRulePO> getCashCostRules(Integer stationId) {

        ValueOperations<String, List<CostRulePO>> valueOperations = redisTemplate.opsForValue();

        String key = "COST_RULE_KEY_" + stationId;

        return valueOperations.get(key);
    }
}
